package com.example.music_mediaplayer.broadcast;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Message;

import com.example.music_mediaplayer.service.MyService;

/**
 * Created by quan on 2018/2/8.
 */

public class ServiceReceiver extends BroadcastReceiver {
    private Message msg = new Message();
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        switch (action){
            case "play_state":
                String state = intent.getStringExtra("state");
                if (msg == null){
                    msg = new Message();
                }else {
                    msg.what = 1;
                    Bundle bundle = new Bundle();
                    bundle.putString("state",state);
                    msg.setData(bundle);
                    MyService.handler.sendMessage(msg);
                }
                break;
            case "seekBarChange":
                int current = intent.getIntExtra("currentProgress",0);
                if (msg == null){
                    msg = new Message();
                }else {
                    msg.what = 2;
                    msg.arg1 = current;
                    MyService.handler.sendMessage(msg);
                }
                break;
            case "play_action":
                if (msg == null){
                    msg = new Message();
                }else {
                    msg.what = 3;
                    MyService.handler.sendMessage(msg);
                }
                break;
        }
    }
}
